﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using XYAC.Framework.MonitorTireMaterialOnline.Extensions;

namespace XYAC.Framework.MonitorTireMaterialOnline.Context
{
    public class CustomReportContext : ReportContext
    {
        public CustomReportContext(IOptionsMonitor<AppConfig> appConfig, DateOnly date)
        {
            AppConfig = appConfig;
            Date = date;
        }

        public IOptionsMonitor<AppConfig> AppConfig { get; }
        public DateOnly Date { get; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlite(AppConfig?.CurrentValue?.LocalReportConnectionStringTemplate.Replace("{DateNow}", Date.ToString("yyyy-MM-dd")));
            }
        }
    }
}
